﻿//Wrapper Object to keep thing sout of global scope
var SpacePort = {};
//Array to hold Ships
SpacePort.ships = [];
//Spaceship Constructor
SpacePort.Ship = function (name, affiliation, image) {
    this.name = name;
    this.affiliation = affiliation;
    this.image = image;

};

//Set Prototype
SpacePort.Ship.prototype.isImpounded = false;
//Draw table to the page
SpacePort.drawTable = function () {
    var h = '<div class="container">'
    h += "<div class='row'>";
    for (var i in SpacePort.ships) {
        var currentShip = SpacePort.ships[i];
        h += "<div class='col-md-4'></div>";
        h += "<h1><i class='"+SpacePort.getIconName(currentShip.affiliation) +"'/>";
        h +=  currentShip.name + "</h1>";
        h += "<img src='"+currentShip.image+"'class='img-thumbnail img-responsive'/>";
        h += "</div>";
    }
    h += "</div>";
    h += "</div>";
};
//Helper function to pull Icon Names

SpacePort.getIconName = function (affiliation) {
    if(affiliaion === "Imperial") {
        return "fa fa-empire";

    }
    else if(affiliation === "Rebel") {
        return "fa fa-rebel";
    }
    else {
        return "fa fa-rocket";
    }
};
/******************* CRUD ********************/
//Add Ships to array
SpacePort.addShip = function () {
    'user strict'
    var name, affiliation, image;
    name = document.getElementById("name");
    affiliation = document.getElementById("affiliation");
    image = document.getElementById("image");
    var s = new SpacePort.Ship(name.value, affiliation.value, image.value);
    SpacePort.ships.push(s);
    image.value = "";
    name.value = "";
    affiliation.value = "";
    SpacePort.drawTable();
//Delete Ship
SpacePort.scrapShip = function () { };
//Show Edit Ship
SpacePort.showEdit = function () { };
//Save Edit Ship
SpacePort.saveEdit = function () { };

/*****************END CRUD*********************/
/**************** AJAX ************************/
//Send to Firebase
SpacePort.sendFirebase = function () { };
//Pull from Firebase
SpacePort.getShips = function () { };
//NEED UPDATE AND DELETE

/***************** END AJAX *******************/



//Seed Function
SpacePort.seed = function () { };
//Clear All
SpacePort.clearAll = function () { };

